package io.renren.modules.peoplemanage.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.peoplemanage.entity.SysClassEntity;
import io.renren.modules.peoplemanage.service.SysClassService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author kiven
 * @email 2213593288@qq.com
 * @date 2020-09-04 16:50:44
 */
@RestController
@RequestMapping("/sys/class")
public class SysClassController {
    @Autowired
    private SysClassService sysClassService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:class:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysClassService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 班级名称列表
     */
    @RequestMapping("/nameList")
    public R getClassNames(){
        List<String> list= sysClassService.findClassNames();
        return R.ok().put("names", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{classId}")
    @RequiresPermissions("sys:class:info")
    public R info(@PathVariable("classId") Integer classId){
		SysClassEntity sysClass = sysClassService.getById(classId);
        return R.ok().put("sysClass", sysClass);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:class:save")
    public R save(@RequestBody SysClassEntity sysClass){

        sysClassService.save(sysClass);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:class:update")
    public R update(@RequestBody SysClassEntity sysClass){
		sysClassService.updateById(sysClass);
        return R.ok();
    }

    /**
     * 升班修改
     */
    @RequestMapping("/top")
    @RequiresPermissions("sys:class:top")
    public R top(@RequestBody Map<String,Object> classInfo){
        sysClassService.topUpdateById(classInfo);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:class:delete")
    public R delete(@RequestBody List<String> idsAndNames){
        System.out.println(idsAndNames);
		sysClassService.removeByIdAndUpdateNames(idsAndNames);
        return R.ok();
    }

    /**
     * 毕业
     */
    @RequestMapping("/after")
    @RequiresPermissions("sys:class:after")
    public R afterClass(String id){
        sysClassService.classGraduate(Integer.parseInt(id));
        return R.ok();
    }

}
